package org.codegallery.javagal.concurrent.jcip;

import java.io.IOException;
import java.math.BigInteger;
import java.util.concurrent.atomic.AtomicReference;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import net.jcip.annotations.NotThreadSafe;

@NotThreadSafe
public class UnsafeCachingFactorizer implements Servlet{
	private final AtomicReference<BigInteger> lastNumber
    = new AtomicReference<BigInteger>();
	
	private final AtomicReference<BigInteger[]>  lastFactors
    = new AtomicReference<BigInteger[]>();

	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		
	}

	public ServletConfig getServletConfig() {
		// TODO Auto-generated method stub
		return null;
	}

	public void service(ServletRequest req, ServletResponse res)
			throws ServletException, IOException {
		BigInteger i = BigInteger.valueOf(0);
        if (i.equals(lastNumber.get())){
        	 //do something
        }else {
        	BigInteger[] factors=new BigInteger[]{}; 
            lastNumber.set(i);
            lastFactors.set(factors);
        }
	}

	public String getServletInfo() {
		// TODO Auto-generated method stub
		return null;
	}

	public void destroy() {
		// TODO Auto-generated method stub
		
	}


}
